package cn.pomelo.album.controller;

import cn.pomelo.album.commom.AjaxResult;
import cn.pomelo.album.model.User;
import cn.pomelo.album.service.UserService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    UserService userService;

    @RequestMapping("/login")
    public AjaxResult login(String id) {
        User byPrimaryKey = userService.selectByPrimaryKey(id);
        if (byPrimaryKey != null) {
            return AjaxResult.success(byPrimaryKey);
        }
        User user = new User();
        user.setId(id);
        int i = userService.insert(user);
        return i > 0 ? AjaxResult.success(user) : AjaxResult.failure("登录失败");
    }
}
